/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.aspirante;

/**
 *
 * @author tamerdark
 */
import pio.action.administrador.*;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.Globals;
import org.apache.struts.action.*;

public class Autorizar implements Filter {

    private String onErrorUrl = "/index.jsp";

    public void init(FilterConfig filterConfig)
            throws ServletException {
    }

    public void doFilter(ServletRequest request,
            ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;
        HttpSession session = req.getSession();
        Integer rol = (Integer) session.getAttribute("rol");
        if (rol == null || rol != 4) { // No es un rol valido
            System.out.println("Intentaron acceder a paginas de aspirante.");
            req.getRequestDispatcher(onErrorUrl).forward(req, res);
        } else { // El rol es nulo o es valido.
            chain.doFilter(request, response);
        }
    }

    public void destroy() {
    }
}
